package com.ssy.lingxi.product.controller.pc.platform;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.product.model.dto.platform.PlatformMaterialProcessMemberDTO;
import com.ssy.lingxi.product.model.request.platform.*;
import com.ssy.lingxi.product.model.resp.platform.PlatformBaseMaterialProcessVO;
import com.ssy.lingxi.product.model.resp.platform.PlatformMaterialProcessDetailVO;
import com.ssy.lingxi.product.model.resp.platform.PlatformMaterialProcessPageQueryVO;
import com.ssy.lingxi.product.service.platform.IPlatformMaterialProcessService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 平台后台 - 物料流程规则配置相关接口
 * @author 彭冬冬
 * @version 2.0.0
 * @date 2022/3/25 13:51
 */
@RestController
@RequestMapping("/product/platform/material/process")
public class PlatformMaterialProcessController extends BaseController {

    @Resource
    private IPlatformMaterialProcessService service;

    /**
     * 分页查询物料流程规则配置
     * @param request HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @GetMapping("/page")
    public Wrapper<PageData<PlatformMaterialProcessPageQueryVO>> pageMaterialProcess(HttpServletRequest request, @Valid PlatformMaterialProcessPageVO pageVO) {
        return service.pageMaterialProcess(getSysUser(request) , pageVO);
    }
    
    /**
     * 新增物料规则页面 - 查询基础物料流程列表
     * @param request Http头部信息
     * @return 查询结果
     */
    @GetMapping("/base/list")
    public Wrapper<List<PlatformBaseMaterialProcessVO>> listBaseMaterialProcess(HttpServletRequest request) {
        return service.listBaseMaterialProcess(getSysUser(request));
    }

    /**
     * 新增物料流程规则
     * @param request HttpHeaders信息
     * @param saveVO 接口参数
     * @return 新增结果
     */
    @PostMapping("/save")
    public Wrapper<Void> save(HttpServletRequest request, @RequestBody @Valid PlatformMaterialProcessVO saveVO) {
        return service.save(getSysUser(request), saveVO);
    }

    /**
     * 查询物料流程规则详情
     * @param request HttpHeaders信息
     * @param processId 物料流程id， 必传且要大于0
     * @return 查询结果
     */
    @GetMapping("/get")
    public Wrapper<PlatformMaterialProcessDetailVO> getInfo(HttpServletRequest request, @RequestParam("processId") Long processId) {
        return service.getInfo(getSysUser(request), processId);
    }

    /**
     * 分页查询物料流程规则适用会员列表
     * @param request HttpHeaders信息
     * @param pageVO  接口参数
     * @return 查询结果
     */
    @GetMapping("/member/page")
    public Wrapper<List<PlatformMaterialProcessMemberDTO>> pageMaterialProcessMembers(HttpServletRequest request, @Valid PlatformMaterialProcessMemberPageVO pageVO) {
        return service.listMaterialProcessMembers(getSysUser(request), pageVO);
    }

    /**
     * 修改物料流程规则
     * @param request HttpHeaders信息
     * @param updateVO 接口参数
     * @return 修改结果
     */
    @PostMapping("/update")
    public Wrapper<Void> update(HttpServletRequest request, @RequestBody @Valid PlatformMaterialProcessUpdateVO updateVO) {
        return service.update(getSysUser(request), updateVO);
    }

    /**
     * 修改物料流程规则状态
     * @param request HttpHeaders信息
     * @param updateStatusVO 接口参数
     * @return 修改结果
     */
    @PostMapping("/status/update")
    public Wrapper<Void> updateStatus(HttpServletRequest request, @RequestBody @Valid PlatformMaterialProcessUpdateStatusVO updateStatusVO) {
        return service.updateStatus(getSysUser(request), updateStatusVO);
    }

    /**
     * 删除物料流程规则
     * @param request HttpHeaders信息
     * @param processId 物料流程规则配置id
     * @return 删除结果
     */
    @GetMapping("/delete")
    public Wrapper<Void> delete(HttpServletRequest request, @RequestParam("processId") Long processId) {
        return service.delete(getSysUser(request), processId);
    }
}
